package com.agil.photoalbum.db.dao;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;

import com.agil.photoalbum.db.entities.Category;
import com.agil.photoalbum.db.entities.Comment;
import com.agil.photoalbum.db.entities.Picture;
import com.agil.photoalbum.db.entities.Role;
import com.agil.photoalbum.db.entities.User;
import com.agil.photoalbum.db.util.SessionManager;
import com.agil.photoalbum.util.Thumbnail;

public class FunctionsTest {
	public static void main(String[] args) {
		
		//System.out.println(Functions.userExists("rrrr"));
		
		//Thumbnail t = new Thumbnail();
//		t.generateThumbnail("S4200016.JPG");
		//testSearchPictureByName("th"); 
		//testGetPicture("1");
		//testSearchPictureByNameForUser("fi");
//		testGetAllPicturesByDate();
//		testGetAllPicturesByDateForUser("100");
//		testGetPicturesForCategory();
//		testGetRootCategory("1");
//		testGetCategoriesForCategory();
//		testGetCommentsForPicture("1");
//		testAddComment("101", "SHIT", "1");
//		testGetAllUsers();
//		testGetRootCategoryForUser()
//		System.out.println(Functions.validateAccount("boncho", "boncho"));
		//testGetAllCategoriesForUser();
		
//		for(Category c : Functions.getCategoriesForCategory(Functions.getRootCategoryForUser("1")))
//		{
//			System.out.println(c.getCategoryName());
//		}
		
		
		//getUserByUserNameTest();
		//isAdminTest();
	}
	
//	private static void isAdminTest()
//	{
//		User u = Functions.getUserById("2");
//		System.out.println(u.isAdmin());
//	}
	
	private static void getUserByUserNameTest() {
		System.out.println(Functions.getUserByUserName("manol").getUserId());
	}
	
	private static void testGetAllCategoriesForUser()
	{
		TreeMap<Long, Category> catsMap = Functions.getAllCategoriesForUser("1");
		
		catsMap.keySet();
	}
	
	private static void testGetCategoriesForCategory()
	{
		Category cat1 = Functions.getRootCategoryForUser("1");
		
		List<Category> cats = Functions.getCategoriesForCategory(cat1);
		for(Category c : cats)
		{
			System.out.println(c.getCategoryName());
		}
	}
	
	
	private static void testGetRootCategoryForUser()
	{
		Category cat1 = Functions.getRootCategoryForUser("1");
		Category cat2 = Functions.getRootCategoryForUser("2");
		System.out.println(cat1.getCategoryName());
		System.out.println(cat2.getCategoryName());
	}
	
	private static void testGetAllUsers()
	{
		List<User> users = Functions.getAllUsers();
		for(User u: users)
		{
			System.out.println(u.getFName());
		}
	}
	
	// works
	private static void testSearchPictureByName(String name) {

		for (Picture p : Functions.searchPictureByName(name))
			System.out.println(p.getPictureName());
	}

	// works
	private static void testGetPicture(String picId) {
		System.out.println(Functions.getPicture(picId).getPictureName());
	}

	// works --> needs to be improved
	private static void testSearchPictureByNameForUser(String name) {
		User user = new User();
		user.setUserId(1);
		for (Picture p : Functions.searchPictureByNameForUser(user, name))
			System.out.println(p.getPictureName());
	}

	// works --> date order ?
	private static void testGetAllPicturesByDate() {
		for (Picture p : Functions.getAllPicturesByDate())
			System.out.println(p.getPicturePath());
	}

	// works
	private static void testGetAllPicturesByDateForUser(String userId) {
		for (Picture p : Functions.getAllPicturesByDateForUser(userId))
			System.out.println(p.getPictureName());
	}

	// works
	private static void testGetPicturesForCategory() {
		Category cat = new Category();
		cat.setCategoryId(2);
		for (Picture p : Functions.getPicturesForCategory(cat))
			System.out.println(p.getPictureName());
	}

	// works--> how would be the root cat recognized
	private static void testGetRootCategory(String catId) {
		System.out.println(Functions.getRootCategory(catId).getCategoryName());
	}

	// cad_id as parameter ??
//	private static void testGetCategoriesForCategory() {
//		for (Category p : Functions.getCategoriesForCategory("3"))
//			System.out.println(p.getCategoryName());
//	}

	// works
	private static void testGetCommentsForPicture(String picId) {
		for (Comment p : Functions.getCommentsForPicture(picId))
			System.out.println(p.getCommentMsg());
	}

	private static void testAddComment(String user_id, String text,
			String pic_id) {
		Functions.addComment(user_id, text, pic_id);
	}

	private static void testGetThumbnailForPicture(String pathToPicture) throws IOException {
		
		FileOutputStream fos = new FileOutputStream("test.jpg");
		
		fos.write(Functions.getThumbnailForPicture(pathToPicture));
	}
}
